package org.etlt.check;

import org.etlt.job.config.xml.AbstractXmlResolver;
import org.w3c.dom.Element;

public class CheckListSettingXmlResolver extends AbstractXmlResolver<CheckListSetting> {


    @Override
    protected void registerParser() {

        registerParser((setting, node, context) -> {
            Element element = (Element) node;
            String name = element.getAttribute("name");
            String report = element.getAttribute("report");
            CheckListSetting setting1 = new CheckListSetting();
            setting1.setName(name);
            setting1.setReportType(ReportType.valueOf(report));
            return setting1;
        }, "/checklist");

        registerParser((setting, node, context) -> {
            Element element = (Element) node;
            String name = element.getAttribute("name");
            String type = element.getAttribute("type");
            CheckPointSetting checkPointSetting = new CheckPointSetting();
            checkPointSetting.setName(name);
            checkPointSetting.setType(CheckPointType.valueOf(type));
            checkPointSetting.setDescription(getFirstChildValueByName(element, "description"));
            checkPointSetting.setExpected(getFirstChildValueByName(element, "expected"));
            checkPointSetting.setActual(getFirstChildValueByName(element, "actual"));
            setting.addCheckPointSetting(checkPointSetting);
            return setting;
        }, "/checklist/checkpoint");

    }
}
